package com.qf.controller;

import com.qf.pojo.Shop;
import com.qf.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Shop> list = shopService.findAll();
//        System.out.println(list);
        model.addAttribute("list",list);
        return "shop_list";
    }

//修改商品,查询商品
    @RequestMapping("/find")
    public String find(Integer shopId,Model model){
        Shop shop = shopService.findShopById(shopId);
        System.out.println(shopId);
        System.out.println(shop);
        model.addAttribute("shop",shop);
        return "shop";
    }

    //根据id修改商品
    @RequestMapping("/update")
    public String update(Shop shop){
        shopService.updateShop(shop);
        return "redirect:findAll";
    }

    //删除
    @RequestMapping("/delete")
    public String delete(Shop shop){
        shopService.deleteShop(shop);
        return "redirect:findAll";
    }

    @RequestMapping("/toadd")
    public String toadd(){
        return "addshop";
    }
    //添加
    @RequestMapping("/add")
    public String add(Shop shop){
        shopService.add(shop);
        return "redirect:findAll";
    }
}
